<template>
  <view class="fixtitle">
	     <view class="" :style="{height:getstateheight()+'px'}"></view>
		 <view class="titletop"  :style="{height:gettitileheight()+'px'}">
			   <view style="width:50rpx;" class="iconfont icon-fanhui" @click="nack"></view>
			   <view class="">浏览历史</view>
			   <view style="width:50rpx;" class=""></view>
		 </view>
  </view>
  <view class="" :style="{height:scrollheight}"></view>
  <scroll-view class="hicon" scroll-y @scrolltolower="scrolltolower">
	  <view class="ti" v-if="now.length">今天</view>
	       <view class="item" v-for="i in now" :key="i.id" @click="goshowdata(i.hoseid)">
			     <sccardVue :data="i" his="true" @delehis="delehis" />
		   </view>
		   <view class="ti" v-if="yq.length">更早</view>
		   <view class="item" v-for="i in yq" :key="i.id" @click="goshowdata(i.hoseid)">
		   			     <sccardVue :data="i" his="true" @delehis="delehis" />
		   </view>
		   <uni-load-more :status="currentdaya.length<10?'no-more':'loading'"></uni-load-more>
  </scroll-view>
</template>

<script setup>
	import {ref} from 'vue'
	import {onLoad} from '@dcloudio/uni-app'
	import {getallhistory} from '@/api/index.js'
	import {getstateheight,gettitileheight} from '@/utils/getinfo.js'
	import sccardVue from '../../components/sccard/sccard.vue'
	const scrollheight=getstateheight()+gettitileheight()+'px'
	const limit=ref(10)
	const offset=ref(1)
	const currentdaya=ref([])
	const now=ref([])
	const yq=ref([])
	onLoad(()=>{
		getallhis()
	})
	const delehis=(id)=>{
		const index=now.value.findIndex(e=>e.id==id)
		if(index!==-1){
			now.value.splice(index,1)
			console.log(111)
			return
		}
		const index2=yq.value.findIndex(e=>e.id==id)
		if(index2!==-1){
			yq.value.splice(index2,1)
			console.log(222)
			return
		}
	}
	const goshowdata=id=>{
		uni.navigateTo({
			url:`/pages/showdata/showdata?id=${id}`
		})
	}
	const scrolltolower=()=>{
		if(currentdaya.value<10)return
		  offset.value++
		  getallhis()
	}
	const getallhis=async ()=>{
		const rudata=await getallhistory(limit.value,offset.value)
		rudata.data.forEach(e=>{
			if(isnowday(e.createdAt)){
				now.value=[...now.value,e]
			}else{
				yq.value=[...yq.value,e]
			}
		})
		currentdaya.value=rudata.data
	}
	const isnowday=(time)=>{
		  const date=new Date(time)
		  const now=new Date()
		  const datatime=''+date.getFullYear()+date.getMonth()+date.getDate()
		  const nowtime=''+now.getFullYear()+now.getMonth()+now.getDate()
		  if(datatime==nowtime)return true
		  return false
	}
	const nack=()=>{
		uni.navigateBack()
	}
</script>

<style lang="scss" scoped>
	.fixtitle{
		position: fixed;
		top: 0;
		left: 0;
		z-index: 99;
		background-color: #fff;
		width: 100%;
		.titletop{
			width: 100%;
			display: flex;
			justify-content: space-between;
			align-items: center;
			padding: 0 20rpx;
			font-size: 25rpx;
			.iconfont{
				font-size: 25rpx;
			}
		}
	}
    .hicon{
		width: 100%;
		height: calc(100vh - v-bind(scrollheight));
		padding:20rpx;
		box-sizing: border-box;
		.ti{
			height: 70rpx;
			font-size: 25rpx;
			font-weight: 700;
			display: flex;
			align-items: center;
			padding-left: 20rpx;
		}
		.item:first-child{
			margin-top: 10rpx;
		}
		.item{
			height: 16%;
			width: 98%;
			margin: 0 auto 10rpx auto;
			box-shadow: 0 0 5rpx 2rpx rgba(0, 0, 0, 0.1);
			border-radius: 10rpx;
		}
	}
</style>
